//
//  YDPositionSettlementCell.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/9.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDPositionSettlementCell.h"
#import "YDPositionModel.h"

@interface YDPositionSettlementCell()
//股票名称
@property (nonatomic , weak) UILabel *stockName;
//股票代码
@property (nonatomic , weak) UILabel *stockCode;
//交易单号
@property (nonatomic , weak) UILabel *transactionCode;
//交易单号详情
@property (nonatomic , weak) UILabel *transactionCodeNumber;
//时间图示
@property (nonatomic , weak) UIImageView *timeImage;
//年月日
@property (nonatomic , weak) UILabel *year;
//时分秒
@property (nonatomic , weak) UILabel *hour;
//盈亏分配
@property (nonatomic , weak) UILabel *profitLoss;
//盈亏数值
@property (nonatomic , weak) UILabel *profitLossNumber;
//买入卖出失败按钮
@property (nonatomic , weak) UILabel *buySaleLabel;

@end

@implementation YDPositionSettlementCell

-(void)setModel:(YDPositionModel *)model
{
    _model = model;
    //股票代码及名称
    self.stockName.text = model.stockName;
    self.stockCode.text = model.stockCode;
    //时间
    self.year.text = model.saleYearStr;
    self.hour.text = model.saleHourStr;

    //交易单号
    self.transactionCodeNumber.text = model.tradeNo;
    
    
    //其他未添加
    if (model.isSuccess) {
        self.profitLoss.hidden = NO;
        self.profitLossNumber.hidden = NO;
        self.buySaleLabel.hidden = YES;
        
        //盈亏
        if ([model.pzProfitOrLoss isEqualToString:@"--"]) {
            self.profitLossNumber.textColor = NumberColor(178, 176, 179);
        }else if ([model.pzProfitOrLoss floatValue] > 0){
            self.profitLossNumber.textColor = [UIColor colorWithHexString:Orange];
        }else{
            self.profitLossNumber.textColor = NumberColor(71, 194, 51);
        }
        self.profitLossNumber.text = model.pzPublisherProfitOrLoss;
        
    }else{
        self.profitLoss.hidden = YES;
        self.profitLossNumber.hidden = YES;
        self.buySaleLabel.hidden = NO;
        
        self.buySaleLabel.text = model.windControlString;
    }

    
    
    
    
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *positionSettlementCell = @"YDPositionSettlementCell";
    YDPositionSettlementCell *cell = [tableView dequeueReusableCellWithIdentifier:positionSettlementCell];
    if (cell == nil) {
        cell = [[YDPositionSettlementCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:positionSettlementCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor whiteColor];
        
        [self stockName];//股票名称
        [self stockCode];//股票代码
        [self transactionCode];//交易单号
        [self transactionCodeNumber];//交易单号详情
        [self timeImage];//时间图示
        [self year];//年月日
        [self hour];//时分秒
        [self profitLoss];//盈亏分配
        [self profitLossNumber];//盈亏数值
        [self buySaleLabel];
        
    }
    return self;
}
/****股票名称******/
-(UILabel *)stockName
{
    if (_stockName == nil) {
        UILabel *stockName = [[UILabel alloc] init];
        [self.contentView addSubview:stockName];
        stockName.textColor = [UIColor colorWithHexString:dark];
        stockName.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        stockName.textAlignment = NSTextAlignmentLeft;
        stockName.text = @"平安银行";
        [stockName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(15));
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(15));
            }else{
                make.top.equalTo(self).offset(rate750(15));
            }
        }];
        _stockName = stockName;
    }
    return _stockName;
}
/****股票代码******/
-(UILabel *)stockCode
{
    if (_stockCode == nil) {
        UILabel *stockCode = [[UILabel alloc] init];
        [self.contentView addSubview:stockCode];
        stockCode.textColor = [UIColor colorWithHexString:blueyGrey];
        stockCode.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        stockCode.textAlignment = NSTextAlignmentLeft;
        stockCode.text = @"000001";
        [stockCode mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.stockName);
            make.left.equalTo(self.stockName.mas_right).offset(rate375(8));
        }];
        _stockCode = stockCode;
    }
    return _stockCode;
}
/****交易单号******/
-(UILabel *)transactionCode
{
    if (_transactionCode == nil) {
        UILabel *transactionCode = [[UILabel alloc] init];
        [self.contentView addSubview:transactionCode];
        transactionCode.textColor = [UIColor colorWithHexString:blueyGrey];
        transactionCode.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        transactionCode.textAlignment = NSTextAlignmentLeft;
        transactionCode.text = @"交易单号:";
        [transactionCode mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.stockName);
            make.centerY.equalTo(self);
        }];
        _transactionCode = transactionCode;
    }
    return _transactionCode;
}
/****交易单号详情******/
-(UILabel *)transactionCodeNumber
{
    if (_transactionCodeNumber == nil) {
        UILabel *transactionCodeNumber = [[UILabel alloc] init];
        [self.contentView addSubview:transactionCodeNumber];
        transactionCodeNumber.textColor = [UIColor colorWithHexString:blueyGrey];
        transactionCodeNumber.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        transactionCodeNumber.textAlignment = NSTextAlignmentLeft;
        transactionCodeNumber.text = @"000000000001";
        [transactionCodeNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.transactionCode.mas_right).offset(3);
            make.centerY.equalTo(self.transactionCode);
        }];
        _transactionCodeNumber = transactionCodeNumber;
    }
    return _transactionCodeNumber;
}
/****时间图示******/
-(UIImageView *)timeImage
{
    if (_timeImage == nil) {
        UIImageView *timeImage = [[UIImageView alloc] init];
        [self.contentView addSubview:timeImage];
        timeImage.image = [UIImage imageNamed:@"cc-time"];
        timeImage.backgroundColor = [UIColor clearColor];
        timeImage.contentMode = UIViewContentModeScaleAspectFill;
        [timeImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.stockName);
            make.width.height.equalTo(@(rate375(10)));
            if (isPhoneX) {
                make.top.equalTo(self.transactionCode.mas_bottom).offset(rateX812(10));
            }else{
                make.top.equalTo(self.transactionCode.mas_bottom).offset(rate750(10));
            }
        }];
        _timeImage = timeImage;
    }
    return _timeImage;
}
/****年月日*****/
-(UILabel *)year
{
    if (_year == nil) {
        UILabel *year = [[UILabel alloc] init];
        [self.contentView addSubview:year];
        year.textColor = [UIColor colorWithHexString:blueyGrey];
        year.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        year.textAlignment = NSTextAlignmentLeft;
        year.text = @"2017.11.09";
        [year mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.timeImage.mas_right).offset(rate375(5));
            make.centerY.equalTo(self.timeImage);
        }];
        _year = year;
    }
    return _year;
}
/****时分秒*****/
-(UILabel *)hour
{
    if (_hour == nil) {
        UILabel *hour = [[UILabel alloc] init];
        [self.contentView addSubview:hour];
        hour.textColor = [UIColor colorWithHexString:blueyGrey];
        hour.font = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
        hour.textAlignment = NSTextAlignmentLeft;
        hour.text = @"11:02:09";
        [hour mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.year.mas_right).offset(rate375(10));
            make.centerY.equalTo(self.timeImage);
        }];
        _hour = hour;
    }
    return _hour;
}

/****盈亏分配******/
-(UILabel *)profitLoss
{
    if (_profitLoss == nil) {
        UILabel *profitLoss = [[UILabel alloc] init];
        [self.contentView addSubview:profitLoss];
        profitLoss.textColor = [UIColor colorWithHexString:blueyGrey];
        profitLoss.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        profitLoss.textAlignment = NSTextAlignmentRight;
        profitLoss.text = @"盈亏分配";
        [profitLoss mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-rate375(41));
            if (isPhoneX) {
                make.top.equalTo(self).offset(rateX812(26));
            }else{
                make.top.equalTo(self).offset(rate750(26));
            }
        }];
        _profitLoss = profitLoss;
    }
    return _profitLoss;
}
/****盈亏数值******/
-(UILabel *)profitLossNumber
{
    if (_profitLossNumber == nil) {
        UILabel *profitLossNumber = [[UILabel alloc] init];
        [self.contentView addSubview:profitLossNumber];
        profitLossNumber.textColor = [UIColor colorWithHexString:leafyGreen];
        profitLossNumber.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        profitLossNumber.textAlignment = NSTextAlignmentRight;
        profitLossNumber.text = @"-200340.1345";
        [profitLossNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.profitLoss.mas_right);
            make.top.equalTo(self.profitLoss.mas_bottom).offset(5);
        }];
        _profitLossNumber = profitLossNumber;
    }
    return _profitLossNumber;
}

/****买入卖出失败******/
-(UILabel *)buySaleLabel
{
    if (_buySaleLabel == nil) {
        UILabel *buySaleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:buySaleLabel];
        buySaleLabel.textColor = [UIColor colorWithHexString:blueyGrey];
        buySaleLabel.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        buySaleLabel.textAlignment = NSTextAlignmentRight;
        [buySaleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-rate375(41));
            make.centerY.equalTo(self);
        }];
        _buySaleLabel = buySaleLabel;
    }
    return _buySaleLabel;
}

-(void)setFrame:(CGRect)frame
{
    CGFloat margin;
    if (isPhoneX) {
        margin = rateX812(5);
    }else{
        margin = rate750(5);
    }
    frame.size.height -= margin * 2;
    frame.origin.y -= margin;
    [super setFrame:frame];
}
@end
